だから私が作ったクエリ:
select distinct id, str_replace(convert(varchar,start_time,102),'.','-') [date],
min(convert(varchar(8), start_time, 108)) [start time],
max(convert(varchar(8), start_time, 108)) [end time],
max(o) [o],
max(a) [a], case when error_msg != '(null)' then error_msg end [error?],
from table group by id order by id desc
これを元に戻します:
id date start time end time o a error?
------------------------------------------------------------
7338971 2012-06-09 11:06:20 11:06:20 2 5 (null)
7338970 2012-06-09 11:06:08 11:06:59 362 725 Yes
7338970 2012-06-09 11:06:08 11:06:59 362 725 (null)
ここで、データは ID でグループ化されます。ただし、null と実際のエラーがあるため、id# 7338970 には 2 つのエントリがあります。null を無視して 7338970 の 1 行のみを表示し、エラー列に yes を表示する方法はありますか? したがって、次のようになります。
id date start time end time o a error?
------------------------------------------------------------
7338971 2012-06-09 11:06:20 11:06:20 2 5 (null)
7338970 2012-06-09 11:06:08 11:06:59 362 725 Yes
前もって感謝します