选择“语句查询”以排除具有重复值的行

时间:2015-04-27 19:42:50

标签: mysql

我需要使用select语句进行SQL查询,该语句排除具有相同Start_TimeEnd_TimeReasonCode

的重复行
EventID       Start_Time         End_Time             ReasonCode 

 122         1/3/2015 0:27      1/3/2015 1:32      No Trouble Found
 123         1/3/2015 0:27      1/3/2015 1:32      No Trouble Found
 124         1/3/2015 0:27      1/3/2015 1:32      No Trouble Found
 125         1/31/2015 14:35    1/31/2015 14:56    LinkupDown

结果输出如下:

EventID       Start_Time         End_Time             ReasonCode 

 122         1/3/2015 0:27      1/3/2015 1:32      No Trouble Found
 125         1/31/2015 14:35    1/31/2015 14:56    LinkupDown

感谢帮助人员。

1 个答案:

答案 0 :(得分:1)

将group by和min函数应用于查询将创建所需的结果集。 SQL Fiddle Demo

select min(eventid) EventID, DATE_FORMAT(Start_Time,'%m/%d/%Y %H:%i') Start_Time, DATE_FORMAT(End_Time,'%m/%d/%Y %H:%i') End_Time, ReasonCode
from mytable
group by ReasonCode
order by eventid