2013-07-08 51 views
0

我使用SQL Server 2008分明,我有以下數據ORDER BY和在同一個SQL查詢

sNames    sDate 
(varchar(MAX)) (date) 
==========  ============= 
ALS   10/02/2012 
SSP   11/03/2012 
MRP   11/05/2012 
ALS   14/06/2012 
ALS   04/10/2012 
ALS   03/11/2012 
MRP   05/09/2012 
PPL   18/08/2012 

我想訂購在遞減名單由SDATE但必須顯示不同sNames。親切指導我

回答

5

使用重複sNames最新的日期,你可以做

select sNames, max(sDate) 
from your_table 
group by sNames 
order by max(sDate) desc 
0

嘗試以下:

Select distinct snames 
from yourtable 
order by sdate desc 
0
select max(sDate),sname from yourTable 
group by sname 
order by max(sDate) desc 
0
SELECT DISTINCT sNames FROM <YOUR TABLE NAME> ORDER BY sDate DESC 
0
SELECT DISTINCT sNames, sDate 
FROM <tableName> 
ORDER BY sDate DESC 
0
select sName,sDate From [your_table] order by sDate Desc 
+0

目前尚不清楚,但我認爲要求是顯示* distinct * sName值的列表。 – Yellowfog