我需要使用select
语句进行SQL查询,该语句排除具有相同Start_Time
,End_Time
和ReasonCode
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
感谢帮助人员。
答案 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