我有以下查询,我需要根据多个where条件过滤数据,但在结果集中我得到的结果不正确,不满足条件。我做错了什么?
SELECT TOP 1 a.ID FROM Counselor a
inner join levelMapping b on a.UserLevel=b.LevelMapped
inner join mUser c on a.ID=c.ID
WHERE
a.HomeLocation=@RES_location and a.PrimarySkill=@RES_PrimarySkill and
b.LEVELINDEX<=
--8
(case when @RES_levelIndex in (8,9) then @RES_levelIndex-1 else @RES_levelIndex-2 end)
and MappedCC_Count<=10 and a.CUrrLoc not like '%Out Of India%' and a.CUrrLoc not like '%Client%'
and c.AG='XYZ'
order by b.levelindex desc,
--case when @RES_levelIndex=9 then b.levelindex end asc,
--case when @RES_levelIndex > 9 then b.levelindex end desc,
a.MappedCC_Count asc
实施例: 下面的结果显示了具有不同位置和技能的Conselor(CC)已映射到用户,尽管我们的逻辑不允许这样: