简体   繁体   中英

How to select data from database higher than exact number

I need to select users from database, which score (column named is time) is higher than 10. How to do that? For now It selecting all users.

For now my code:

    $query = "SELECT userName,min(time) time FROM game group by userName order by time ASC LIMIT 15";
if (!$mysqli->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $mysqli->error);

You can use WHERE clause to filter your result

SELECT userName,min(time) time 
FROM game
WHERE  `time` >10
group by userName 
order by time ASC LIMIT 15

or if you want to filter on resultset of aggregate function you can use HAVING clause

SELECT userName,min(time) time 
FROM game
group by userName 
HAVING  min(time) >10
order by time ASC LIMIT 15 

Just add WHERE clause, like:

    $query = "SELECT userName,min(time) time FROM game WHERE time>10 group by userName order by time ASC LIMIT 15";
if (!$mysqli->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $mysqli->error);

You need do:

SELECT userName,min(time) time 
FROM game WHERE time > 10 
group by userName 
order by time ASC LIMIT 15;

Add HAVING MIN(time) >10 to your query like this:

$query = "SELECT userName, MIN(time) time FROM game GROUP BY username HAVING MIN(time) >10 ORDER BY time ASC LIMIT 15";

Your query will look like this:

SELECT userName, MIN(time) time 
FROM game
GROUP BY userName 
HAVING MIN(time) >10
ORDER BY time ASC LIMIT 15 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM