从播放器表中选择最大值仅返回第一行 [英] select max values from player table return only first row

查看:70
本文介绍了从播放器表中选择最大值仅返回第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

MySQL





这是我写的sql语句返回结果我想要前30玩家它只返回第一个玩家







this is the sql statment i wrote to return result i want the first 30 player it only return first player


SELECT name  FROM `p_players` WHERE (is_blocked <> '0' AND is_active = '1') order by
total_people_count DESC,  gold_num DESC ,
 attack_points DESC , defense_points DESC , hero_level DESC , week_thief_points DESC , hero_points DESC , villages_count DESC LIMIT 0,30





< img src =http://www11.0zz0.com /2014/06/16/12/100993199.png\"/>



然后它只返回x结果必须是多个结果



<img src="http://www11.0zz0.com/2014/06/16/12/100993199.png"/>

then it only return x the result must be more than one result

推荐答案

由于您没有限制在SELECT语句中使用TOP nCLAUSE返回的值的数量,因此SQL将返回所有匹配的行。你需要查看你的数据,因为如果SQL返回一行,那就是; s因为只有一行匹配is_blocked<>'0'和is_active ='1'
Since you don't restrict the number of values returned with a "TOP n" CLAUSE ON your SELECT statement, SQL will return all matching rows. You need to look at your data, because if SQL is returning one row, that;s because there is only one row which is matches "is_blocked <> '0' AND is_active = '1'"


您的SQL语句是正确的,但似乎您的值中有前导空格,并且它与您的条件不符。

不要像字符串类型列那样保存数值。所有这些问题都归于此。如果您不能将列类型更改为int或其他一些数字类型,请执行以下操作。使用修剪功能



Your SQL Statement is correct, but it seems you have leading spaces in your values and it will not match your conditions.
Don't save numeric values as in string type column. All these issues due to that. if you can't change your column types to int or some other numeric type do as below. Use Trim function

SELECT name  FROM supportContacts
WHERE (trim(is_blocked) <> '0' AND trim(is_active) = '1') .....


这篇关于从播放器表中选择最大值仅返回第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆