sql - 通过添加其他两个表的列在 Redshift 中创建一个表
问题描述
我想通过添加其他两个表的列在 Redshift 中创建一个表。
想在以下条件下创建新表
- 如果 table1.sid = table2.sid
那么 t1.totalcorrect+t2.totalcorrect, t1.totalquestions+t2.totalquestions。即 s4 到 s7 - else 两个表中的数据原样
使用连接结果表只给我 S4 到 S7 而不是其他所需的列。请帮我
解决方案
那是一个full join
:
select
coalesce(t1.sid, t2.sid) sid,
coalesce(t1.totalcorrect, 0) + coalesce(t2.totalcorrect, 0) totalcorrect,
coalesce(t1.totalquestions, 0) + coalesce(t2.totalquestions, 0) totalquestions
from t1
full join t2 on t2.sid = t1.sid
推荐阅读
- javascript - 在另一个函数旁边调用一个函数javascript解释
- java - Hibernate 以小写形式返回查询结果
- azure-data-explorer - Kusto 查询语言:如何将结果列保存到变量中?
- rust - 锈匹配!宏在枚举方面的行为异常
- flutter - 错误:参数类型“字符串?” 不能分配给参数类型“字符串”,因为“字符串?” 是 nulable 并且 'String' 不是 'Email'+user.email
- linux - 如何让我的 bash 脚本自动为新用户分配唯一的用户名?
- visual-studio-code - 在 VSCode 上访问 Solidity 时遇到问题
- java - java中使用通配符的正则表达式
- c# - 为什么这个脚本中没有应用重力,为什么跳跃不起作用?
- javascript - 如何从 .js 文件中的 html onclick 访问函数