我有桌面交易(Trans)
noacc month date1 date2 date3
101 09 50 20 30
102 08 20 21 25
我想在月份为09选择日期3时和当月份08选择日期2时进行查询。我想像这样进行查询
Case When trans.month = 09
THEN
(SELECT trans.date3 From trans)
ELSE
(SELECT trans.date2 From trans)
END
FROM trans
你可以给我一些建议吗?谢谢你
答案 0 :(得分:0)
SELECT
CASE month
WHEN 9 THEN date3
WHEN 8 THEN date2
END as CalculatedMonth
FROM trans
答案 1 :(得分:0)
试试这个:
Select
case when trans.month = 09 then trans.date3
else trans.date2
end as [date]
FROM trans
答案 2 :(得分:0)
试试这个:
SELECT case When trans.month = '09' THEN date1 ELSE date2 end
FROM trans
答案 3 :(得分:0)
select case when trans.month=09 then date3 else date2 end from tans
答案 4 :(得分:0)
很难猜到你想要什么。也许提供一个典型的预期输出?!
无论如何猜测你想要逐行评估,正确的语法是
Select
Case When trans.month = 09
THEN
trans.date3
ELSE
trans.date2
END
AS Date
FROM trans;
你可以表达更短的内容
Select IIF(month = 09, date3, date2) as Date
From trans