继续这个问题(MAX with extra criteria),我被告知我需要打开一个新问题以获取更多信息。
上述问题涉及获得玩家的最高分,如果最高分在“BatHowOut”字段中的值为“not out”,则应显示为96 *而不是96。
我需要能够通过PlayerID分组获得最高分,这就是这个问题的内容。
SELECT
PlayerID,
MAX(CAST(MatchPlayerBatting.BatRuns AS SIGNED)) AS HighestScore
FROM
MatchPlayerBatting
GROUP BY
PlayerID
根据上一个问题,请考虑:
BatRuns BatHowOut
96 not out
96 lbw
BatRuns BatHowOut
96 not out
102 lbw
答案 0 :(得分:0)
尝试做这样的事情:
<强> EDITED .. 强>
select playerID,
max(concat((BatRuns),
case when BatRuns = (Select max(BatRuns) from mytable where
outornot = 'no') then '*' else '' end))
from mytable
group by playerID
order by cast(BatRuns as signed) desc,
(CASE WHEN outornot = 'no' then 1 else 2 end);
<强> SQL Fiddle 强>