如果结果=0/null,则更改位置?

cgvd09ve  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(283)

我有以下疑问:

select
C.[Exchange Rate Amount]

from [Canada].[vCurrencyRate] as C

Where
C.[Currency Code] = 'CAD'
AND cast(C.Date as date) = cast( getdate() as date)

我希望它做的是,如果结果是0,那么有一天回滚日期

Where
C.[Currency Code] = 'CAD'
AND IF C.[Exchange Rate Amount] = 0 then cast(C.Date as date) = datediff( day, -1, cast( getdate() as date)) else cast(C.Date as date) = cast( getdate() as date)

但是我不知道怎么让它工作

kxe2p93d

kxe2p93d1#

如果你想要一排,用 order by 限制为一行:

select top (1) C.[Exchange Rate Amount]
from [Canada].[vCurrencyRate] as C
Where C.[Currency Code] = 'CAD' AND cast(C.Date as date) <= cast( getdate() as date)
order by c.date DESC;

因为方括号和 getdate() ,我假设这是sql server。其他数据库将使用 limit 或者 fetch first 1 row only .

相关问题