假设我从select返回下表
| 病例ID|文档ID|文档类型Id|文件类型|失效日期|
| - ------|- ------|- ------|- ------|- ------|
| 1个|1个|1个|伊七九七|2023年1月2日|
| 1个|第二章|第二章|I94|2023年1月2日|
| 1个|三个|三个|一些其他值|2023年1月2日|
我想***只选择***DocumentType = 'I797'
所在的行,如果没有'I797'
,我想***只选择***DocumentType = 'I94'
所在的行;如果找不到这两个值中的任何一个,我想取所有具有DocumentType
的其他值的行。
最好使用SQL Server。
我想我正在寻找一个XOR子句,但无法找出如何在SQL Server中执行该操作或获取所有其他值。
3条答案
按热度按时间332nm8kg1#
类似于@siggemannen答案
最短:
k97glaaz2#
大概是这样的:
其思想是根据文档类型按1、2、3对行进行排序。由于我们对“其余行”的排序相同,因此如果I797和I94缺失,您将获得所有行。
2skhul333#