March 24, 2015 at 5:21 pm
Hi,
I’ve got a query I’m working on and need some help.
Below is the query and what it does is assigns a sequence number to the line based on the designated partition. What I want to be able to do now is only return those line items that = 2 for the resulting linenumber sequence.
Any ideas? I trying wrapping it in a having clause but that’s not workinguse [SampleDB]
SELECT LocationID, LanguageID ,LocationLanguageRecID,
row_number() over (partition by LOCATIONID
order by LocationLanguageRecID) LineNumber
FROM LocationLanguages
March 24, 2015 at 5:27 pm
Have you tried to use a subquery or CTE?
March 24, 2015 at 6:06 pm
Hi Luis,
Not sure how I would do that..
March 24, 2015 at 6:56 pm
SELECT * FROM
(
SELECT LocationID, LanguageID ,LocationLanguageRecID,
row_number() over (partition by LOCATIONID
order by LocationLanguageRecID) LineNumber
FROM LocationLanguages
) X
WHERE LineNumber = 2
-- Itzik Ben-Gan 2001
March 24, 2015 at 7:21 pm
Thanks Alan. Much appreciated.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply