-2

だから私が作ったクエリ:

    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

前もって感謝します

4

2 に答える 2

1

追加してみてください:

and error is not null

あなたのクエリに。

于 2013-07-10T15:26:10.893 に答える
0

「エラーがnullの場合、エラー列にnullを表示する必要があります」というコメントに基づいて:

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 isnull(error_msg,'null') end [error?],
from table 
group by id order by id desc
于 2013-07-10T15:35:39.230 に答える