You are here: Re: how/what should be the query for this result « MsSQL Server « IT news, forums, messages
Re: how/what should be the query for this result

Posted by Erland Sommarskog on 10/02/70 11:51

(choudharymv@gmail.com) writes:
> I have 1 table "Progress"
>
> P_no b_no status build_date
> ----------------------------------------------------------------
> 25 1 First_slab 2006/4/5
> 25 1 second slab 2006/5/6
> 25 2 first slab 2006/1/2
> 25 2 third slab 2006/2/3
>
> o/p should be as
> Pno,bno, status, max(build_date)
>
> sample o/p can be as below
> 25 1 second slab 2006/5/6
> 25 2 third slab 2006/2/3

SELECT a.pno, a.bno, a.status, a.build_date
FROM progress a
JOIN (SELECT pno, bno, build_date = MAX(build_date)
FROM progress
GROUP BY BY pno, bno) AS b ON a.pno = b.pno
AND a.bno = p.bno
AND a.build_date = b.build_date


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

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

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