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

解决方案 »

  1.   

    select 列名 % 3 as Col1 from A 
      

  2.   


    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 19select *,col%3 as col的余数 from @T
    /*
    col         col的余数
    ----------- -----------
    13          1
    15          0
    17          2
    18          0
    19          1
    */
      

  3.   

    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 19select *,col%3 as col的余数 from @T
    /*
    col         col的余数
    ----------- -----------
    13          1
    15          0
    17          2
    18          0
    19          1
    */一列值的时候就是把  列名%m这样表示即可