首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求一条 SQL 语句,多谢

2012-02-19 
求一条 SQL 语句,谢谢某张表中存在用户字段user_id,及对应金额字段user_Fee其数值为user_iduser_Fee00185.

求一条 SQL 语句,谢谢
某张表中存在用户字段   user_id,及对应金额字段   user_Fee   其数值为  
user_id                     user_Fee
001                               85.37
002                               108.43
003                               364.25
001                               207.56
...                                   ...

现在想查询出所有100元分段为分组的用户数,如:
0-100元:   30个用户
100-200元:   20个用户
.....

请问怎样实现,谢谢

[解决办法]
declare @t table(user_id varchar(10),user_free float)
insert into @t select '001 ',85.37
union all select '002 ',108.43
union all select '003 ',364.25
union all select '001 ',207.56

select LTRIM(FLOOR (user_free/100)*100)+ '- '+LTRIM((FLOOR (user_free/100)+1)*100)+ '元 ',LTRIM(count(*))+ '个用户 '
from @t
group by LTRIM(FLOOR (user_free/100)*100)+ '- '+LTRIM((FLOOR (user_free/100)+1)*100)+ '元 '

/*
0-100元 1个用户
100-200元 1个用户
200-300元 1个用户
300-400元 1个用户

(所影响的行数为 4 行)

*/

热点排行
Bad Request.