日期:2014-05-18 浏览次数:20472 次
select sum(case when id between 1 and 15 then 1 else 0 end) [1-15], sum(case when id between 16 and 100 then 1 else 0 end) [16-100], ...自己补全 sum(case when id between 9000 and 10000 then 1 else 0 end) [9000-1000] from table where state = 1
------解决方案--------------------
select sum(case when id (between 1 and 15) and state=1 then 1 else 0 end) as [1-15], sum(case when id (between 16 and 100) and state=1 then 1 else 0 end) as [16-00] ...... from(select row_number()over(order by getdate()) as id,* from tbl)a
------解决方案--------------------
看到这个提问的时候太晚了,不知道在SQL2005中能不能用序号去解决