Ich habe Schema ähnlich den folgenden:innerhalb einer Gruppe, die die Top-n Zeilen Auswahl von Klausel
create table bar
(
instrument varchar(255) not null,
bar_dttm datetime not null,
bar_open int not null,
bar_close int not null
)
Ich mag die Tabelle abzufragen, und gibt die letzten 5 Zeilen pro Instrument.
ich es kann durch Instrument Instrument tun, mit:
select top 5 instrument, bar_dttm, bar_open, bar_close
from bar
where instrument = 'XXX'
order by bar_dttm desc
Ich mag würde dies in einer Abfrage auf einmal für alle Instrumente zu tun. Ist das möglich? Ich bin mit SQL Server 2008.
, welche Version von SQL Server? –
SQL Server 2008 - zur Frage hinzugefügt. – Jon