سؤال

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

هل كانت مفيدة؟

المحلول

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).

نصائح أخرى

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 |
+-----------------+----------+
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top