Re: Aggregate Fun (Getting the Max out of MAX)...head scratcher



On Nov 6, 7:37 pm, "Plamen Ratchev" <Pla...@xxxxxxxxxxxxx> wrote:
Hi Sean,

Here is one way to do this (if I understand correctly your requirements) in
SQL Server 2005 using ROW_NUMBER. Based on your notes I assumed the latest
inception date can be used to identify the most recent update.

WITH cte
(key_no, customer_no, inception_date, org_no, seq_no)
AS
(
SELECT key_no, customer_no, inception_date, org_no,
ROW_NUMBER() OVER(
PARTITION BY customer_no
ORDER BY inception_date DESC,
key_no DESC) AS seq_no
FROM tx_cust_memb
)
SELECT key_no, customer_no, inception_date, org_no
FROM cte
WHERE seq_no = 1;

BTW, your results seem to be incorrect, you have customer 5 listed twice and
customer 4 is missing.

HTH,

Plamen Ratchevhttp://www.SQLStudio.com

This is PERFECT! Thanks so much!

Sean

.



Relevant Pages

  • Re: Aggregate Fun (Getting the Max out of MAX)...head scratcher
    ... SQL Server 2005 using ROW_NUMBER. ... WITH cte ... customer 4 is missing. ... Plamen Ratchev ...
    (comp.databases.ms-sqlserver)
  • SqlCE message 27750
    ... Customer had this message, just on 2002. ... Cannot load sscemw20.dll or ssceca20.dll is missing or not registered. ... If I do believe that SQl Server CE 2.0 is installed properly, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: same application on multiple schemas
    ... As for the "comparison" with Sql Server, it was not intended to ask ... why Oracle does "not" support sql server behaviour:) I know oracle (I ... For every customer that will use our application, ... will use schema "SchemaA" ...
    (comp.databases.oracle.server)
  • Re: same application on multiple schemas
    ... As for the "comparison" with Sql Server, it was not intended to ask ... why Oracle does "not" support sql server behaviour:) I know oracle (I ... For every customer that will use our application, ... will use schema "SchemaA" ...
    (comp.databases.oracle.server)
  • Re: Index for username/password
    ... say that users want to be able to define customer ... A username in a login table is a little different. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)

Loading