declare @i int
set @i = 1000
select (pay / @i) * @i, count(*) from cpay group by pay / @i

解决方案 »

  1.   

    Select pay%1000 ,Count(*) From cpay where pay%1000=0 group by pay%1000
      

  2.   

    动态sql:
      select (case when pay < 1000 then 1000
                  when pay >=1000 and pay < 2000 then 2000
                  when pay >=2000 and pay < 3000 then 2000
                  when pay >=3000 and pay < 4000 then 2000
              end),count(*)
        from T
    group by (case when pay < 1000 then 1000
                  when pay >=1000 and pay < 2000 then 2000
                  when pay >=2000 and pay < 3000 then 2000
                  when pay >=3000 and pay < 4000 then 2000
              end)
      

  3.   

    tj_dns(愉快的登山者) :小于1000或者大于2000如何处理
      

  4.   

    declare @ integer
    set @=1000
    select max(cast(accu_base / @ as int)) * @
           ,count(*) 
    from cbenefit 
    group by cast(accu_base / @ as int)
    order by max(cast(accu_base / @ as int)) * @