<?php #Round to the next multiple of 5, exclude the current number function roundNumberToUp($n, $x = 5) { return round(($n + $x / 2) / $x) * $x; } roundNumberToUp(10); #10 roundNumberToUp(10.2); #15 roundNumberToUp(11.5); #15 #Round to the nearest multiple of 5, include the current number function roundNumberToNearest($n, $x = 5) { return (round($n) % $x === 0) ? round($n) : round(($n + $x / 2) / $x) * $x; } roundNumberToNearest(10); #10 roundNumberToNearest(10.3); #10 roundNumberToNearest(10.5); #15 roundNumberToNearest(11.7); #15 #Round up to an integer, then to the nearest multiple of 5 function roundNumberToNearestAsInteger($n, $x = 5) { return (ceil($n) % $x === 0) ? ceil($n) : round(($n + $x / 2) / $x) * $x; } roundNumberToNearestAsInteger(10.3); #15 roundNumberToNearestAsInteger(11.7); #15
Its so simple. Just need to do below thins: |
SELECT SUBSTRING_INDEX(GROUP_CONCAT(x.id ORDER BY x.nx DESC), ',', 2) as row_name from some_table GROUP BY some_field |
It will select First two values only. |
It total value of GROUP_CONCAT is "1,2,3,4,5" Then Using SUBSTRING_INDEX would be like "1,2" |
You can use DISTINCT in GROUP_CONCAT function like SUBSTRING_INDEX(DISTINCT(GROUP_CONCAT(x.id ORDER BY x.nx DESC)), ',', 2) |