Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
kezzaman
Starting Member
3 Posts |
Posted - 2013-05-24 : 06:09:47
|
Hello everyone,I'm struggling over the following issue.I have a table from which I get the results from the collumns Artcode and Orderdate. Now I want to get all articles and their last 5 orderdates. I'm using the following query but then I get only the last orderdate. Can someone help me. Thanx.SELECT ARTCODE, MAX(ORDERDATE) FROM TBL_SALESGROUP BY ARTCODE |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-05-24 : 06:31:16
|
[code]SELECT ARTCODE, ORDERDATEFROM (SELECT ARTCODE, ORDERDATE, ROW_NUMBER() OVER(PARTITION BY ARTCODE ORDER BY ORDERDATE DESC) RN FROM TBL_SALES ) TempWHERE Temp.RN<=5[/code]--Chandu |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|