--这样?
declare @t table(proj_id int,res_id int,task_id int,starttime varchar(10),availability int)
insert into @t select 1,101,1,'2006-4-30',30
union all select 1,101,1,'2006-5-1',100
union all select 1,101,1,'2006-5-2',90
union all select 1,101,2,'2006-4-30',50
union all select 1,101,2,'2006-5-1',50
union all select 1,101,3,'2006-4-30',40
union all select 1,101,3,'2006-5-1',20
union all select 1,101,3,'2006-5-2',60
union all select 2,101,4,'2006-4-30',20
union all select 2,101,4,'2006-5-1',20
union all select 2,101,5,'2006-5-2',10select res_id,starttime,sum(availability) as availability from @t group by res_id,starttime
declare @t table(proj_id int,res_id int,task_id int,starttime varchar(10),availability int)
insert into @t select 1,101,1,'2006-4-30',30
union all select 1,101,1,'2006-5-1',100
union all select 1,101,1,'2006-5-2',90
union all select 1,101,2,'2006-4-30',50
union all select 1,101,2,'2006-5-1',50
union all select 1,101,3,'2006-4-30',40
union all select 1,101,3,'2006-5-1',20
union all select 1,101,3,'2006-5-2',60
union all select 2,101,4,'2006-4-30',20
union all select 2,101,4,'2006-5-1',20
union all select 2,101,5,'2006-5-2',10select res_id,starttime,sum(availability) as availability from @t group by res_id,starttime
解决方案 »
- SQL SERVER where字句的问题
- 求一个求数据库中表的数据行数的sql?急,没分了
- 连接字符串中Provider=MSDASQL.1和Provider=SQLOLEDB.1有什么区别?
- MySql在命令提示符查询数据不能显示中文吗?
- 这个触发器怎么写?(连锁触发)
- 如何删掉表中重复的记录,保留重复记录中ID最小的一条记录?
- 请教一个事务回滚的问题?
- 大量日志 用户 'sa' 登录失败. [客户端: 202.102.230.141]
- 关于触发器,请高手有没有好的解决方案?
- 注册服务器,怎么解决“超时已过期”的错误信息!
- 頭痛的 String or binary data would be truncated 錯誤
- 创建函数是 有问题?
from table
group by proj_id,starttime
是正解 实在抱歉
刚才没有尝试
谢谢楼上 和 xeqtr1982(sunman)