选择一个组中的前n行我有类似以下模式:by子句
create table bar
(
instrument varchar(255) not null,
bar_dttm datetime not null,
bar_open int not null,
bar_close int not null
)
我想查询表,每仪器返回最近的5行。
我可以通过仪器做仪器,具有:
select top 5 instrument, bar_dttm, bar_open, bar_close
from bar
where instrument = 'XXX'
order by bar_dttm desc
我想对所有仪器一次在一个查询做到这一点。这可能吗?我运行SQL Server 2008的
什么版本的SQL Server? – 2009-06-16 21:39:33
SQL Server 2008 - 添加到问题。 – Jon 2009-06-16 21:41:16