如何在sql中忽略group by中的特定值

如何在sql中忽略group by中的特定值,sql,null,group-by,Sql,Null,Group By,所以我的问题是: 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

所以我的问题是:

    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分组。但是,id#7338970有两个条目,因为存在null和实际错误。是否有任何方法可以忽略空值,只为7338970显示一行,为error列显示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
提前感谢

尝试添加:

且错误不为空


根据注释“如果错误为null,那么它应该在错误列中显示null”:


请发布原始SQL查询。您使用的是什么rdbms?如果一个ID只有一行,你想看看它的错误是否为空吗?我使用的是sybase 5.5,是的,我想看看它是否为空,我想看看错误是否为空,虽然如果idI没有错误,我想看看错误是否为空,如果文件的传输没有错误。但是,我不明白你在说什么。“如果没有错误,则错误为空”是什么意思?如果错误为空,则应在错误列中显示空,而不是完全排除它
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