select giftname count(giftid)[count], sum(amount) sum2 from gift group by giftname
解决方案 »
- sybase_ase如何将sp_spaceused的返回值 存入表中?
- 几个表之间的数据调用
- 在线等,储存过程递归问题,一无级分类表,已知一id值,求该id下所有子类id,并将这些id以逗号拼接成一个字符串
- 数据库设计问题!高手请进!!
- 求一个关于删除表中数据的SQL Server 2000的存储过程,参数为表名
- 在sql2005中,用sql语句如何更新一列的description属性
- sql server 2008 服务中的sql server服务无法启动
- 怎樣使涉及到兩個表的SQL語句的新增和刪除語句只能對一個表有效?
- 给定一个表,怎么找出这个表的主键是哪些字段?
- 寻贴-《关于缩小SQL Server日志的存储过程》,谁有?
- 一个存储过程的问题
- sql事务
giftname,
count(giftid) as [count],
sum(amount) as [sum2]
from 表
group by giftname
--TRYselect giftname,count(giftname)as [count],sum(amount) as sum2 from table0 group by giftname
select giftname , count(giftid) , sum(amount) from tb group by giftname
go
create table #(giftname varchar(10), giftid int, amount int, type varchar(10))
insert # select 'aaa' , 1, 12 , 'lll'
insert # select 'aaa' , 2 , 23 , 'lll'
insert # select 'bbb', 3 , 14, ' iii'
select giftname , count(giftid)[count], sum(amount) sum2 from # group by giftname
/*giftname count sum2
---------- ----------- -----------
aaa 2 35
bbb 1 14
*/
go
create table [tb]([giftname] varchar(3),[giftid] int,[amount] int,[type] varchar(3))
insert [tb]
select 'aaa',1,12,'lll' union all
select 'aaa',2,23,'lll' union all
select 'bbb',3,14,'iii'select
giftname,
count(giftid) as [count],
sum(amount) as [sum2]
from tb
group by giftname
--测试结果:
giftname count sum2
-------- ----------- -----------
aaa 2 35
bbb 1 14(所影响的行数为 2 行)
(
giftname nvarchar(20),
giftid int,
amount int,
[type] nvarchar(20)
)
insert into #T
select 'aaa' , 1 , 12 , 'lll' union all
select 'aaa', 2 , 23 , 'lll' union all
select 'bbb', 3 , 14 , 'iii'
select giftname,COUNT(giftname),SUM(amount) from #T group by giftname