当前位置:首页 » 编程语言 » sql中余数例题
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql中余数例题

发布时间: 2023-01-04 02:59:54

1. 问个sql语句,查询到的数据,除以2,余数四舍五入,如何写

假设你要更新的表为books,列为price,当前要更新的数据ID(标识列)为1
update
books
set
price=(select
round((select
price
from
books
where
id=1)/2,1))
where
id=1
下面来说明
1.
select
price
from
books
where
id=1
查出你要更新的初始价格是多少
2.
用select
round(数字,精度)来四舍五入
例如select
round(63.543,1)
结果为63.5
3.
将四舍五入的值更新到表中
update
books
set
price=(select
round((select
price
from
books
where
id=1)/2,1))
where
id=1
希望楼主能有用

2. sql小数除以整数求余数

取余数应该是

select 10.5 % 3