sql - 在 SQL 中连接两个表
问题描述
表1:
CID Detail
1 d1
2 d2
3 d3
表2:
ID CID FileType
1 1 1
2 1 2
3 2 2
所需结果:全部来自 Table1,如果 FileType 为 null 或 <> 1,则为 null
CID Detail FileType
1 d1 1
2 d2 null
3 d3 null
解决方案
我认为您正在寻找 1-1 分配。像这样的东西:
select t1.*, t2.FileType
from tbl1 t1 left join
(select tbl2.*,
row_number() over (partition by cid order by id) as seqnum
from tbl2
) t2
on t2.cid = t1.cid and t2.seqnum = 1 and
t2.FileType = 1;
推荐阅读
- angular - 无法为子组件单元测试加载父 SCSS 文件
- spss - 如何计算文本实例
- php - 如何在语音播放时淡入和淡出背景音乐并在最后淡出音频并使用ffmpeg将它们混合在一起
- spring - Wildfly 在启动时抛出 UnsupportedOperationException(命名上下文是只读的)
- php - “找不到文件”在heroku上运行时,但它适用于本地
- azure - 将第 3 方 Azure AD 租户目录用户/组数据与应用程序的数据存储同步
- git - svn:GIT 中的外部模拟
- azure - Azure Functions - 日志整合 - 控制主机日志?
- c# - 如何等待来自执行 SQLite 查询的方法的布尔响应
- c - 我想循环这段代码,直到用户想要