sql以0.5向下取整

a578452523 2013-05-28 11:06:35
sql server 2000中,我想以0.5向下取整,
如 :
0 取整后为 0,
0.0<=@x<0.5 取整后为 0,
0.5<=@x<1 取整后为 0.5,
1<=@x<1.5 取整后为 1 ,
1.5<=@x<2 取整后为 1.5 ,
2<=@x<2.5 取整后为 2 ,
2.5<=@x<3 取整后为 2.5 ,
.......
以此类推。。
怎么实现?望越简洁越好!
之前也有发过“sql以0.5向上取整的帖子”,高手们用 ceiling(@a*2)/2 就解决了,但是现在要向下取整了,不知道咋办了,又来求助各位了!!! 注意是向下哦!!
...全文
846 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 4 楼 ap0405140 的回复:

create table a5(x decimal(5,1))

insert into a5(x)
 select 0 union all
 select 0.2 union all
 select 0.6 union all
 select 1.1 union all
 select 1.7 union all
 select 2.3 union all
 select 2.9


select x,
       x-x%0.5 'y'
from a5
 
/*
x                                       y
--------------------------------------- ---------------------------------------
0.0                                     0.0
0.2                                     0.0
0.6                                     0.5
1.1                                     1.0
1.7                                     1.5
2.3                                     2.0
2.9                                     2.5

(7 row(s) affected)
*/
膜拜
唐诗三百首 2013-05-28
  • 打赏
  • 举报
回复

create table a5(x decimal(5,1))

insert into a5(x)
 select 0 union all
 select 0.2 union all
 select 0.6 union all
 select 1.1 union all
 select 1.7 union all
 select 2.3 union all
 select 2.9


select x,
       x-x%0.5 'y'
from a5
 
/*
x                                       y
--------------------------------------- ---------------------------------------
0.0                                     0.0
0.2                                     0.0
0.6                                     0.5
1.1                                     1.0
1.7                                     1.5
2.3                                     2.0
2.9                                     2.5

(7 row(s) affected)
*/
yiyishuitian 2013-05-28
  • 打赏
  • 举报
回复
select ceiling(1.22*2)/2 select floor(1.22*2)/2
  • 打赏
  • 举报
回复

select floor(0.5*2)/2--0.5

select floor(0.4*2)/2--0

哥眼神纯洁不 2013-05-28
  • 打赏
  • 举报
回复
select floor(@a*2)/2
  • 打赏
  • 举报
回复
引用 4 楼 ap0405140 的回复:

create table a5(x decimal(5,1))

insert into a5(x)
 select 0 union all
 select 0.2 union all
 select 0.6 union all
 select 1.1 union all
 select 1.7 union all
 select 2.3 union all
 select 2.9


select x,
       x-x%0.5 'y'
from a5
 
/*
x                                       y
--------------------------------------- ---------------------------------------
0.0                                     0.0
0.2                                     0.0
0.6                                     0.5
1.1                                     1.0
1.7                                     1.5
2.3                                     2.0
2.9                                     2.5

(7 row(s) affected)
*/
nice

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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