如何从一列读取多列但具有DISTINCT值?

时间:2016-07-26 05:40:13

标签: sql sql-server

嗨,我有一张这样的桌子:

    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

我想获得Date,Name和Enginner,但是要使用DISTINCT NAME。我想要Popescu,玛丽亚,Adnrei,Vasilica与Date,Name和Egineer

由于

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

试试这个

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