本文介绍了根据条件/值从Mysql表中获取前3名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据足球运动员的位置,我需要获得前3名前锋,前3名中场球员,前4名后卫球员

I need to get top 3 Forwards,Top 3 Midfielders,Top 4 Defenders based on Soccer players Position

我有一个单独的表

位置表的结构

PositionID和PositionName

PositionID And PositionName

1 Tor(意味着守门员)

1 Tor(Which Means Goal Keeper)

2 Abwehr(指防御者)

2 Abwehr(Which Means Defenders)

3米特尔费尔德(意味着中场)

3 Mittelfeld(Which Means Midfielders)

4格里夫(指向前移动)

4 Angriff(Which Means Forwards)

我有Soccerplayers Table,其中有Name(玩家名称),PositionId,TScore(玩家得分)

and i have Soccerplayers Table where there is Name(Player Name),PositionId,TScore(Player Score)

我需要基于TScore的每个位置的前3名玩家

i need Top 3 players from Each position based on TScore

任何查询建议??

推荐答案

那么您可以尝试以下查询集:

Well you can try this query set:

(SELECT Name, PositionId, TScore FROM Soccerplayers WHERE PositionID = 1 ORDER BY TScore LIMIT 3)
UNION
(SELECT Name, PositionId, TScore FROM Soccerplayers WHERE PositionID = 2 ORDER BY TScore LIMIT 4)
UNION
(SELECT Name, PositionId, TScore FROM Soccerplayers WHERE PositionID = 3 ORDER BY TScore LIMIT 3)

这篇关于根据条件/值从Mysql表中获取前3名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:07