sql - 用于检查数据库中是否存在 3 个连续值的 SQL 查询?
问题描述
我正在尝试查询数据库以检查数据库字段中是否存在 3 个值(例如:us、uk、usr),如果存在它应该返回 true,否则它必须返回不存在的值。
Select ( case when exists ( select Detail
from Application
where EmpID = '123' and Detail = ?
)
then 1
else 0
end )
解决方案
Select ( case when exists ( select Detail
from Application
where EmpID = '123' and Detail IN ('us', 'uk', 'usr')
)
then 1
else 0
end )
编辑
无论如何要返回表中不存在的值而不是 0 或 1(例如:美国)-?
select case when Detail IN ('us', 'uk', 'usr')
then Detail
else '-'
end
from Application
where EmpID = '123'
编辑 2
但是它返回数据库中存在的值,我如何修改它以返回数据库中不存在的值?
Select ( case when exists ( select Detail
from Application
where EmpID = '123'
)
then (select case when Detail IN ('us', 'uk', 'usr')
then Detail
else '-'
end
from Application
where EmpID = '123'
)
else '-'
end )
推荐阅读
- knockout.js - FullCalendar v4 的淘汰赛自定义绑定
- sql - 事件表中最后一个事件和倒数第二个事件之间的差异
- aurelia - Aurelia @observable 属性,避免在附加到视图时被调用
- c# - 我将如何在 EF Core 中创建这种多对多关系?
- android - 为什么我在运行后在 Flutter 上收到“无法执行 aapt”错误?
- sql - SQL Server - 选项条款
- php - 为什么只有第一个 mysqli_fetch() 结果存储在数组中
- python - 打印命令写入一行
- azure - Function App 调用另一个被 IP 地址阻止的 Function App
- ios - [NSPlaceholderString initWithString:]: nil argument' 在 iOS13 上