求大神给小弟我一条SQL语句 有高手在嘛
求大神给我一条SQL语句 有高手在嘛?
有一个表 就1个字段 表里面有6条数据 分别是 60 69 70 79 80 89 怎么查询出来 大于等于60小于<70 大于等于70小于<80 大于等于80小于<90 的各有多少条 只可以用一条SQL语句写出来 求指教
------解决方案--------------------
------解决方案--------------------
有一个表 就1个字段 表里面有6条数据 分别是 60 69 70 79 80 89 怎么查询出来 大于等于60小于<70 大于等于70小于<80 大于等于80小于<90 的各有多少条 只可以用一条SQL语句写出来 求指教
------解决方案--------------------
select
[60-70]=sum(case when col>=60 and col<70 then 1 else 0 end),
[70-80]=sum(case when col>=70 and col<80 then 1 else 0 end),
[80-90]=sum(case when col>=80 and col<90 then 1 else 0 end)
from TB
------解决方案--------------------
select
[60-69]=sum(case when txt between 60 and 69 then 1 else 0 end),
[70-80]=sum(case when txt between 70 and 79 then 1 else 0 end),
[80-90]=sum(case when txt between 80 and 89 then 1 else 0 end)
from tb