有没有简单的方法可以找出3个字段的最大值?

duibudui 2008-08-08 10:55:40
3个字段是日期型的,有没有内置函数可以直接写在where 条件里的?
可能类似oracle里的greatest().
...全文
146 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wgzaaa 2008-08-08
  • 打赏
  • 举报
回复
内置函数的没有
tm62490309 2008-08-08
  • 打赏
  • 举报
回复
where case when 字段1>=字段2 and 字段1>=字段3 then 字段1
when 字段2>=字段3 then 字段2
else 字段3
end > getdate()
wgzaaa 2008-08-08
  • 打赏
  • 举报
回复
----------建函数
create function fun_max(@a datetime,@b datetime,@c datetime)returns datetime as
begin
return (select max(a) from(select @a a union select @b union select @c)ta)
end
--测试
create table #a(a datetime,b datetime,c datetime)
insert #a select '2008-08-05','2008-08-08','2008-08-04'
select dbo.fun_max(a,b,c) from #a
---------------
2008-08-08 00:00:00.000
hyqwan11112 2008-08-08
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sdxiong 的回复:]
函数就没有了,但可以通过case实现

where case when 字段1>=字段2 and 字段1>=字段3 then 字段1
when 字段2>=字段3 then 字段2
else 字段3
end > getdate()
[/Quote]
sdxiong 2008-08-08
  • 打赏
  • 举报
回复
函数就没有了,但可以通过case实现

where case when 字段1>=字段2 and 字段1>=字段3 then 字段1
when 字段2>=字段3 then 字段2
else 字段3
end > getdate()
sunhonglei2004 2008-08-08
  • 打赏
  • 举报
回复
3个字段的最大值??
lgxyz 2008-08-08
  • 打赏
  • 举报
回复
好像没有,自己写个函数吧,或是把这个字段都放到同一列下再取最大值
Shellbkboy 2008-08-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lgxyz 的回复:]
好像没有,自己写个函数吧,或是把这个字段都放到同一列下再取最大值
[/Quote]

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧