简体   繁体   English

在T-SQL中使用distinct获取数据

[英]Getting data using distinct in T-SQL

I have a table that has two columns, a date time and a string. 我有一个表有两列,一个日期时间和一个字符串。

Multiple entries can have the same string, its a file path. 多个条目可以具有相同的字符串,即文件路径。

I want to return distinct entries with the latest date time stamp. 我想返回带有最新日期时间戳的不同条目。 Can anyone help me out here? 有人可以帮我从这里出去吗?

Cheers. 干杯。

EDIT: Sample data 编辑:示例数据

ExportedDate                CsvLocation
------------------------    --------------------------------------
2015-09-14 14:37:19.000     C:\fakePath\9_14_201514_56_35\file.txt
2015-09-14 14:53:25.000     C:\fakePath\9_14_201514_56_35\file.txt
2015-09-14 15:00:31.000     C:\fakePath\9_14_201514_56_35\file.txt
2015-09-14 15:54:42.000     C:\fakePath\9_14_201515_23_22\file.txt

Then I want returned: 然后我想要回复:

2015-09-14 15:00:31.000     C:\fakePath\9_14_201514_56_35\file.txt
2015-09-14 15:54:42.000     C:\fakePath\9_14_201515_23_22\file.txt

You don't need distinct for this, just group data bys csv location and select the max date for it 您不需要对此进行区分,只需将数据分组为csv位置并为其选择最大日期

SELECT CsvLocation, MAX(ExportedDate)
FROM your_table
GROUP BY CsvLocation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM