Number time count create_by
1 2012-8-14 20:20:20 3 tom
1 2012-8-14 20:19:20 3 jerry
1 2012-8-13 20:19:20 3 jerry
2 2012-8-11 20:19:20 1 Ketty
2 2012-8-10 20:19:20 1 nick求编号的累积数量,并且显示最新的Create_by和日期1 2012-8-14 20:20:20 9 tom
2 2012-8-11 20:19:20 2 Ketty
1 2012-8-14 20:20:20 3 tom
1 2012-8-14 20:19:20 3 jerry
1 2012-8-13 20:19:20 3 jerry
2 2012-8-11 20:19:20 1 Ketty
2 2012-8-10 20:19:20 1 nick求编号的累积数量,并且显示最新的Create_by和日期1 2012-8-14 20:20:20 9 tom
2 2012-8-11 20:19:20 2 Ketty
解决方案 »
- 一个多表查询的问题
- *******************请问关于MSDE和Sqlserver 2005 express的问题*****************
- 求助:SQL SERVER 2008 R2 查询LINKED SERVER 报错
- 如何解决查询超时的问题呢?
- SQL2005完整备份+事务日志备份 还原出错问题!(高手测试测试)
- 如何提高 nvarchar(max) 列的join效率
- SQL 多表查询
- SQL查询问题
- 当我向数据库(orcale)里中不断的写数据,可是………………
- 讨论:一个网站使用一个数据库,还是同时使用几个数据库好?
- 小问题:请使用 CONVERT 函数来运行此查询
- 几个关于优化、维护数据库的问题。求指教
--try
select t.Number,max(t.time) ,sum(t.count),t1.[create_by]
from 你的表 t,(select row_number() over(partition by Number order by Number,[time] desc) rn,
Number,[time],[count],[create_by]
from 你的表) t1
where t.Number=t1.Number and t1.rn=1
group by t.Number;
(
select number, max(time) as time, sum(count) as sumcount
from table
group by number
)
select temp.number, temp.time, temp.sumcount, table.create_by
from temp
inner join table on table.number = temp.number
and table.time= temp.time
select a.Number,max(a.time) ,sum(a.count),b.[create_by]
from
tab a,
(select rank() over(partition by Number order by Number,[time] desc) RankID,Number,[time],[count],[create_by] from tab) b
where a.Number=b.Number and b.RankID=1
group by a.Number;