0

我正在尝试执行以下查询,但它给了我警告Null值被聚合或其他SET操作消除。

select 
  s.CurrentDate,
  s.game_id,
  s.Searchstring,
  sm.type_of_game,
  case when(count(t.game_id)>0) then 'Y' else 'N' end as scorestatus,
  case when(count(i.game_id)>0) then 'Y' else 'N' end as scorestatusindividual,
  sm.image_path,g.datetime,'' as score_keeper
from dbo.Search s  with(nolock) 
left outer join dbo.TeamGameResult t  with(nolock) on s.game_id = t.game_id
left outer join dbo.IndividualGameResult i  with(nolock) on i.game_id = s.game_id 
join dbo.Game g  with(nolock) on g.game_id=s.game_id 
join  dbo.AdditionalDetails ad on ad.AdditionalDetails_id = g.AdditionalDetails_id
join dbo.SportMaster sm  with(nolock) on  sm.SportsMaster_id = ad.SportsMaster_id
where (( Searchstring+' '+ convert(nvarchar(500),s.CurrentDate,101) Like '%01/15/2013%' 
  and Searchstring+' '+ convert(nvarchar(500),s.CurrentDate,101) Like '%Soccer%'))
  and convert(varchar(10),g.datetime,101) in ('01/15/2013','01/14/2013')
group by s.game_id,
         s.Searchstring,
         sm.type_of_game,
         s.CurrentDate,
         sm.image_path,
         g.datetime
order by g.datetime desc 
4

1 回答 1

1

它只是警告您,因为您正在使用

... when(count(i.game_id)>0) then 'Y' else 'N' end ...

Count 是一个聚合函数,不能计算 game_id 为空的值。您可以使用 ISNULL 函数 ( http://msdn.microsoft.com/en-GB/library/ms184325.aspx ) 例如:

count(ISNULL(i.game_id, 0))

但随后它也会计算所有 NULL 值。所以如果你不想要它,你需要在 WHERE 部分添加额外的检查

于 2013-03-27T07:27:24.717 回答