You are here: Re: Aggregate Fun (Getting the Max out of MAX)...head scratcher « MsSQL Server « IT news, forums, messages
Re: Aggregate Fun (Getting the Max out of MAX)...head scratcher

Posted by sean.pinto on 11/07/07 17:41

On Nov 6, 7:37 pm, "Plamen Ratchev" <Pla...@SQLStudio.com> 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация