Good all the time of the day gentlemen

There is a sign from which I want to group the data by the number field:

$zapros = mysql_query("SELECT * FROM `table` GROUP BY `number`,$db); // работает 

Is it possible to make the same grouping by number, but not by the whole number, but from 2nd to 5th character (3 characters)? Ie: from 8388608, 8387608, 8388609 - must find 2 records

ps in my example it turns out they look through 3 records (there are actually several thousand of them), and they have from 2nd to 5th character: 886, 876, 886. then group them together, we get 886, 876. would hear once, something like:

 $zapros = mysql_query("SELECT * FROM `table` GROUP BY `substr(number,2,3)`,$db); 
  • If you need to get all the records and group them in a certain cleverly twisted order, and not in ascending / descending order, try grouping the result already received by the script. - zenith
  • But it is possible in more detail about what kind of group you want - I did not quite understand from your example ( - Ale_x
  • added a question - sergey

2 answers 2

If I understand the question correctly:

 table: numbers --id --num sql: SELECT SUBSTRING( num, 1, 3 ) , COUNT( * ) FROM numbers GROUP BY SUBSTRING( num, 1, 3 ) LIMIT 0 , 30 result(например): substring(num,1,3) | count(*) 123 | 2 838 | 3 
  • go away from native mysql_ *. (use for example PDO, mysqli, etc)

    Use WHERE:

     $zapros = mysql_query("SELECT * FROM `table` GROUP BY `number` WHERE `number` > чего то AND WHERE `number` < чего то,$db); 

    This is an option.

    • it will cut off some of the records, but the point is this? I need to group something - sergey