You are here: Re: Retrieve ONLY first/max « MsSQL Server « IT news, forums, messages
Re: Retrieve ONLY first/max

Posted by Nick Chan on 09/18/07 04:49

select top 1 type from (
SELECT type,sum(units) s
FROM order, product
WHERE order.id = product.id
GROUP BY type ) t1 order by s desc


On Sep 18, 12:03 pm, Mark <mnbaya...@gmail.com> wrote:
> So, I have a query
>
> SELECT type
> FROM order, product
> WHERE order.id = product.id
> GROUP BY type
> ORDER BY sum(units) DESC
>
> but I only want the first row. MS SQL 2005 doesn't seem to support
> "LIMIT" or "FIRST" which is unfortunate. I can shove that whole query
> into another one that checks the MAX, but then I can only get the MAX
> number of units within a group, when I want to know the type that has
> the max units in any group.

 

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

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