You are here: Re: SQL query dilemma « MsSQL Server « IT news, forums, messages
Re: SQL query dilemma

Posted by ree321 on 08/22/06 23:22

Thanks that worked great when I changed the SUM(a.Amount) to
Max/Min(a.Amount) as I want the latest amount and not the sum of the
Amounts.

Hugo Kornelis wrote:
> On 21 Aug 2006 23:26:25 -0700, ree321@gmail.com wrote:
>
> Hi ree321,
>
> Try if this works:
>
> SELECT TOP 10 a.Project, SUM(a.Amount) AS TotalAmount
> FROM YourTable AS a
> WHERE a.Date = (SELECT MAX(b.Date)
> FROM YourTable AS b
> WHERE b.Project = a.Project)
> GROUP BY a.Project
> ORDER BY TotalAmount DESC
>
> (Untested - see www.aspfaq.com/5006 if you prefer a tested reply)
>
> --
> Hugo Kornelis, SQL Server MVP

 

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

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