深圳soho网,small office home office
当前位置 : 深圳soho网 >>  web技术  >> 文章正文

如何实现一周点击排名 SQL

日期:2008-6-9  作者:szsoho  来源:www.szsoho.com   点击:

Q:我有一个表名为 YZPM 的表

表中有 P,D,N 三个列名

P 记录软件名称
D 记录日期
N 记录当天的点击量

请问如何实现所有软件一周内总点击量排名? 谢谢!
A:
MSSQL:
功能:可以实现最近7天的累加点击量,并按点击量从高到低排列
select * from
(
select  P,sum(N) as total from YZPM
where datediff(d,D,getdate())<=7 and datediff(d,D,getdate())>=0
group by p
) as t
order by total desc
=================================
数据
P             D     N
ie6       2008-5-25  10
ie6       2008-5-24         15
firefox       2008-5-25         3
firefox       2008-5-24         2
opera       2008-5-26         10
opera       2008-5-22         10
=============================
结果
ie6       25
opera       20
firefox       5