MySQL选择最高用户排名最高的组双峰
我的问题是,在结果中,如果用户位于超过 1 个排名较高的组中,则他可以多次进入该组。
SELECT xf_user_group_relation.user_id , xf_user_identity.account_name, xf_user_group_relation.user_group_id, MAX( xf_user_group.display_style_priority ) AS display_style_priority
FROM xf_user_group_relation
INNER JOIN xf_user_group ON xf_user_group_relation.user_group_id = xf_user_group.user_group_id
INNER JOIN xf_user_identity ON xf_user_group_relation.user_id = xf_user_identity.user_id
WHERE xf_user_group.display_style_priority >=1000 AND identity_service_id = 'Minecraft'
GROUP BY xf_user_group_relation.user_id, xf_user_group_relation.user_group_id, xf_user_identity.account_name
结果:
|user_id|account_name|user_group_id|display_style_priority|
|1|yuriman|5|10000
|1|yuriman|6|9000
|2|skull905|5|10000
|13|ryan1271|5|10000
|21|mr_matt|9|6000
|37|Gaurav251|12|1000
|38|tvmaniac9|9|6000
|38|tvmaniac9|11|2000
|44|robyrq|9|6000
|44|robyrq|12|1000
|86|sabasNL|11|2000
|86|sabasNL|15|5200
|128|Scarykittens|9|6000
|133|Sargent5|10|5000
|133|Sargent5|11|2000
|142|kevy76|9|6000
|142|kevy76|11|2000
|144|liljew29|10|5000
|144|liljew29|11|2000
|149|a7xtdgfan332|10|5000
|160|TheNeoStrike|11|2000
|189|CptToddney|11|2000
结果应如下所示:
|user_id|account_name|user_group_id|display_style_priority|
|1|yuriman|5|10000
|2|skull905|5|10000
|13|ryan1271|5|10000
|21|mr_matt|9|6000
|37|Gaurav251|12|1000
|38|tvmaniac9|9|6000
|44|robyrq|9|6000
|86|sabasNL|11|2000
|128|Scarykittens|9|6000
|133|Sargent5|10|5000
|142|kevy76|9|6000
|144|liljew29|10|5000
|149|a7xtdgfan332|10|5000
|160|TheNeoStrike|11|2000
|189|CptToddney|11|2000
我希望结果仅包含用户排名最高的组,即具有最高 display_style_priority 的组。 我不知道如何解决这个问题。
此致
My problem is that in the result a user can be in it more then one time if he is in more then 1 higher ranked group.
SELECT xf_user_group_relation.user_id , xf_user_identity.account_name, xf_user_group_relation.user_group_id, MAX( xf_user_group.display_style_priority ) AS display_style_priority
FROM xf_user_group_relation
INNER JOIN xf_user_group ON xf_user_group_relation.user_group_id = xf_user_group.user_group_id
INNER JOIN xf_user_identity ON xf_user_group_relation.user_id = xf_user_identity.user_id
WHERE xf_user_group.display_style_priority >=1000 AND identity_service_id = 'Minecraft'
GROUP BY xf_user_group_relation.user_id, xf_user_group_relation.user_group_id, xf_user_identity.account_name
Result:
|user_id|account_name|user_group_id|display_style_priority|
|1|yuriman|5|10000
|1|yuriman|6|9000
|2|skull905|5|10000
|13|ryan1271|5|10000
|21|mr_matt|9|6000
|37|Gaurav251|12|1000
|38|tvmaniac9|9|6000
|38|tvmaniac9|11|2000
|44|robyrq|9|6000
|44|robyrq|12|1000
|86|sabasNL|11|2000
|86|sabasNL|15|5200
|128|Scarykittens|9|6000
|133|Sargent5|10|5000
|133|Sargent5|11|2000
|142|kevy76|9|6000
|142|kevy76|11|2000
|144|liljew29|10|5000
|144|liljew29|11|2000
|149|a7xtdgfan332|10|5000
|160|TheNeoStrike|11|2000
|189|CptToddney|11|2000
The result should look like this:
|user_id|account_name|user_group_id|display_style_priority|
|1|yuriman|5|10000
|2|skull905|5|10000
|13|ryan1271|5|10000
|21|mr_matt|9|6000
|37|Gaurav251|12|1000
|38|tvmaniac9|9|6000
|44|robyrq|9|6000
|86|sabasNL|11|2000
|128|Scarykittens|9|6000
|133|Sargent5|10|5000
|142|kevy76|9|6000
|144|liljew29|10|5000
|149|a7xtdgfan332|10|5000
|160|TheNeoStrike|11|2000
|189|CptToddney|11|2000
I want the result to have the users highest ranked group only which is the one with the highest display_style_priority.
Im not sure how to fix that.
Best Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你需要更改组
i think you need to change the group by