2016-07-26 55 views
1

嗨,我有一個表是這樣的:如何從一列讀取多個列但具有DISTINCT值?

ID  OrderID Date      Name   Engineer 
    3870 12302 2016-07-19 11:29:30.547 Popescu Bogdan  Yes 
    4459 12302 2016-07-25 13:02:52.657 Popescu Bogdan  Yes 
    3868 12302 2016-07-19 11:26:36.593 Popescu Bogdan  Yes 
    3869 12302 2016-07-19 11:27:05.797 Popescu Bogdan  Yes 
    4127 12302 2016-07-20 12:10:56.527 maria madalina  Yes 
    4483 12302 2016-07-25 14:01:31.147 andrei vasile  Yes 
    4538 12302 2016-07-25 18:58:34.007 vasilica vrabie  Yes 

我想日期,姓名和ENGINNER但唯一名字。我只想波佩斯庫,瑪麗亞,Adnrei,Vasilica與日期,名稱和Egineer

感謝

回答

1

你可以嘗試使用:

select DISTINCT NAME, [Date], Enginner 
from myTable 

您也可以嘗試

select NAME, [Date], Engineer from myTable where 
ID in (Select max(ID) FROM myTable group by Name) 

enter image description here

+0

Doesn; t work,i try this – Vladut

+0

爲我工作只是選擇了一列 – Vladut

+0

@Vladut: - 更新了我的答案。請立即檢查! –

1

試試這個

SELECT Date,Name,Engineer FROM table_name WHERE OrderID = '12136' GROUP BY Name,Engineer,Date; 
+0

錯誤消息:ORders_P3Header.HasEngineer在選擇列表中無效,因爲它不包含在聚合函數或GROUP BY子句中。 – Vladut

+0

@Vladut - 立即嘗試更改已添加 – Slan

+0

閱讀問題,他想要'Date,Name and Enginner' – Sankar

相關問題