0

继这个问题(MAX with extra criteria)之后,有人告诉我我需要打开一个新问题以获取更多信息。

上述问题与获得玩家的最高分有关,如果最高分在“BatHowOut”字段中的值为“未出局”,则应显示为 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
4

1 回答 1

0

尝试做这样的事情:

已编辑..

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小提琴

于 2013-08-21T10:53:59.780 回答