日期:2014-05-18  浏览次数:20553 次

关于SQL求余的问题
在SQL中是否有求余函数,在有的博客中谈到用%来计算求余
我所遇到的问题是:
在SQL中写一条select语句,来求出一列值的余数(商值也行)。
望楼下粘出有效代码!
我所说的不是一个值,是一列
即:列名%3=X

------解决方案--------------------
select 列名 % 3 as Col1 from A
------解决方案--------------------
SQL code

declare @T table (col int)
insert into @T
select 13 union all
select 15 union all
select 17 union all
select 18 union all
select 19

select *,col%3 as col的余数 from @T
/*
col         col的余数
----------- -----------
13          1
15          0
17          2
18          0
19          1
*/

------解决方案--------------------