May 2, 2017 at 2:42 pm
Helo
Please help me build a query to return the last (based on date) row for each article
ex: table ART
REF | DESCRIPTION | QTY | DATE | MOV
001 | ARTICLE | 5 | 2016-01-01 | IN
001 | ARTICLE | 7 | 2016-07-01 | IN
004 | OTHER ART | 1 | 2017-02-03| IN
004 | OTHER ART | 10 | 2015-02-03| OUT
005 | ART5 | 1 | 2017-02-03 | IN
005 | ART5 | 13 | 2016-02-03 | ou
Should return
001 | ARTICLE | 7 | 2016-07-01 | IN
004 | OTHER ART | 1 | 2017-02-03 |IN
005 | ART5 | 1 | 2017-02-03 | IN
If i query like this
select max(date),ref from ART group by ref order by ref
it works but if i insert in the query other field it returns all the rows of the table
i think the problem is in the GROUP BY
Thanks in advance
May 2, 2017 at 3:45 pm
Solved using ...ROW_NUMBER() OVER (PARTITION BY ....
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply