0
SELECT count(w.c1) AS count
     , w.c1 AS color
FROM
  data w
GROUP BY
  w.c1
ORDER BY
  w.id DESC
LIMIT
  50000;

I'm wondering, is there any kind of mysql query to group by zerofill values, i have all values in c1 as rgb code '0002500034' (r=000/g=250/b=034), after query it shows like 000250034->250034

ekad
  • 14,436
  • 26
  • 44
  • 46
vagiz
  • 313
  • 2
  • 15

2 Answers2

1

What about the LPAD MySQL function ? LPAD(str, len, padstr)

SELECT count(w.c1) AS count
 , LPAD(w.c1, 9, '0')  AS color
FROM
  data w
GROUP BY
  w.c1
ORDER BY
  w.id DESC
LIMIT
  50000;

You can also turn your column type into CHAR(9).

Blackarma
  • 46
  • 2
0
SELECT count(w.c1) AS count
     , concat(w.c1) AS color
FROM
  data w
GROUP BY
  w.c1
  order by w.c1 desc
LIMIT
  50000;

just tried and it works fine, also i'll try your version

edit: my query:

+-----------------+-----------+
| Variable_name   | Value     |
+-----------------+-----------+
| Last_query_cost | 16.599000 |
+-----------------+-----------+

vs your's

+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| Last_query_cost | 3.599000 |
+-----------------+----------+
vagiz
  • 313
  • 2
  • 15