Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help plzzz!!

Author  Topic 

cool_iron007
Starting Member

1 Post

Posted - 2010-12-09 : 12:31:24
Hello Everyone!

I have view called vw_maintenance which holds records for maintenace of a car from two different tables. maintenance view has fields like ( branchname, vehicle id, mileage, last service date, next service date).

I need to run query which displays the branchname from vw_maintenance which has maximum number of maintenance entries...

Please help guys..I am stuck...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-12-09 : 12:52:11
[code]SELECT TOP 1 branchname
FROM
(
SELECT COUNT() OVER (PARTITION BY branchname) AS Cnt,branchname
FROM Table
)t
ORDER BY Cnt DESC
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -