declare @table1 table (type int,price int)
insert into @table1 values (2,232)
insert into @table1 values (2,34)
insert into @table1 values (3,676)
insert into @table1 values (4,67)
insert into @table1 values (5,345)
insert into @table1 values (6,345)select case when type between 2 and 3 then '2、3' when type between 4 and 5 then '4、5' else cast(type as varchar) end as type,sum(price)sum from @table1 group by case when type between 2 and 3 then '2、3' when type between 4 and 5 then '4、5' else cast(type as varchar) end
insert into @table1 values (2,232)
insert into @table1 values (2,34)
insert into @table1 values (3,676)
insert into @table1 values (4,67)
insert into @table1 values (5,345)
insert into @table1 values (6,345)select case when type between 2 and 3 then '2、3' when type between 4 and 5 then '4、5' else cast(type as varchar) end as type,sum(price)sum from @table1 group by case when type between 2 and 3 then '2、3' when type between 4 and 5 then '4、5' else cast(type as varchar) end
解决方案 »
- 求助关于字符串是否存在问题
- 用友U8的数据转移问题 急哦~
- 高分求一条较复杂的sql语句
- 求一条 将 点分十进制的IP地址转换为 数值 的SQL语句??
- 在一个服务器上可以最多建立多少个数据库阿,每个数据库中有多少个表阿?
- 急!在线等。。。增加主键的问题 PRIMARY KEY
- win7 64位,在ODBC的DNS中对sql server配置成功,但连接失败
- Hi, 为什么@total值不会变化, volume_percent与cumlative_percent值一模一样
- msdb数据库坏掉,提示"有疑问",请问怎么解决
- sql server 2000 登陆远程服务器失败
- 如何添加列名?
- 怎样把INT类型的字段修改成标识字段。
谢谢
insert into @table1 values (2,232)
insert into @table1 values (2,34)
insert into @table1 values (3,676)
insert into @table1 values (4,67)
insert into @table1 values (5,345)
insert into @table1 values (6,345)
insert into @table1 values (7,232)
insert into @table1 values (8,232)
select case when type between 2 and 3 then '2、3' when type between 4 and 5 then '4、5' else 'others' end as type,sum(price)sum from @table1 group by case when type between 2 and 3 then '2、3' when type between 4 and 5 then '4、5' else 'others' end
table1
group by case type when 2 then 2 when 3 then 2 when 4 then 4 when 5 then 4 else type end