You are here: Re: Interesting SQL problem : How to track movement history « MsSQL Server « IT news, forums, messages
Re: Interesting SQL problem : How to track movement history

Posted by Robert Klemme on 04/20/07 13:59

On 20.04.2007 15:49, markc600@hotmail.com wrote:
> If you are using SQL Server 2005, you can do this
>
> with cte(location_id,date_created,grp)
> as (
> select location_id,
> date_created,
> rank() over(partition by location_id order by date_created)
> - rank() over(order by date_created)
> from mytable)
> select location_id,
> max(date_created) as date_created
> from cte
> group by location_id,grp
> order by max(date_created)

I'd do

select location_id, max(date_created) date_created
from your_table
group by location_id
order by max(date_created)

Am I missing something?

robert

 

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

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