SQL查排名问题

来源:百度知道 编辑:UC知道 时间:2024/05/09 17:53:30
SQL Server中,有一个表储存商户交易信息,表结构如下
表名 BM 日期 商户名称 交易金额

现要查1年内交易排名前100名得商户
谢谢

select 编号,数量,(select count(*)+1 as 排名 from 表名 b where b.数量>a.数量) as 排名 from 表名 a order by 数量 desc

看不下去了。。

select top 100 * from 表名 where datediff(yy,日期,getdate())<=1 order by 交易金额 desc

select [id], [name], count(*) from a where [time] = '2007-01-01' group by [id], [name] order by [id] desc

select top 100 商户名称, 交易金额 , 日期 from BM where year(日期)='2007' order by 交易金额

select [id], [name], count(*) from a where [time] = '2007-01-01' group by [id], [name] order by [id] desc