1

可能重复:
SQL Server 中的不同

我想选择不同的 PokemonId 变量,但它不起作用

这里是查询

select distinct top 36 
    tblFoundPokemonsOnRoutes.pokemonId,MonsterTotalStats,
    MAX(maxLevel) as maxLevel,
    Case Class WHEN 'Ancient' Then '9' 
      WHEN 'Legendary' Then '8' 
      WHEN 'Zenith' Then '7' 
      WHEN 'Emissary' Then '6' 
      WHEN 'Starter' Then '5' 
      WHEN 'Superior' Then '4' 
      WHEN 'Regular' Then '3' 
      ELSE Class 
    END as Result 
from 
    tblFoundPokemonsOnRoutes 
left join 
    tblPokedex on tblFoundPokemonsOnRoutes.pokemonId = tblPokedex.PokemonId 
where 
    tblFoundPokemonsOnRoutes.routeId in 
          (select routeId from tblRoutes where ZoneNumber = 1) 
group by 
    maxLevel, tblFoundPokemonsOnRoutes.pokemonId, MonsterTotalStats, Class 
order by 
    Result desc, MonsterTotalStats desc

这里返回的结果

在此处输入图像描述

非常感谢您的回答

4

1 回答 1

1

你不应该包括MaxLevel在你的GroupBy条款中。这样做:

select distinct top 36 
    tblFoundPokemonsOnRoutes.pokemonId,MonsterTotalStats,
    MAX(maxLevel) as maxLevel,
    Case Class WHEN 'Ancient' Then '9' 
      WHEN 'Legendary' Then '8' 
      WHEN 'Zenith' Then '7' 
      WHEN 'Emissary' Then '6' 
      WHEN 'Starter' Then '5' 
      WHEN 'Superior' Then '4' 
      WHEN 'Regular' Then '3' 
      ELSE Class 
    END as Result 
from 
    tblFoundPokemonsOnRoutes 
left join 
    tblPokedex on tblFoundPokemonsOnRoutes.pokemonId = tblPokedex.PokemonId 
where 
    tblFoundPokemonsOnRoutes.routeId in 
          (select routeId from tblRoutes where ZoneNumber = 1) 
group by 
     tblFoundPokemonsOnRoutes.pokemonId, MonsterTotalStats, Class 
order by 
    Result desc, MonsterTotalStats desc
于 2012-12-09T05:40:12.157 回答