可能重複:
Distinct in SQL Server爲什麼distinct在這個sql查詢中不起作用? - 複雜的查詢
我想選擇disctinct 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
這裏返回的結果
非常感謝您的答案
我沒有看到任何重複的行......你認爲哪些是重複的,應該由'DISTINCT'消除? 'DISTINCT'只適用於'SELECT'中的** ALL **列 - 只有當所有值相同時纔會排除一行。 –
,因爲它們不會在所有列中重複,例如'maxlevel'各不相同 – codingbiz
@marc_s哦,我明白了。無論如何,我可以讓PokemonIds獨特嗎? – MonsterMMORPG