SELECT count(w.c1) AS count
, w.c1 AS color
FROM
data w
GROUP BY
w.c1
ORDER BY
w.id DESC
LIMIT
50000;
我想知道,是否有任何类型的mysql查询按zerofill值进行分组,我将c1中的所有值都设为rgb代码“0002500034
”(r=000/g=250/b=034)
,查询后显示为{{ 1}}
答案 0 :(得分:1)
LPAD MySQL功能怎么样? 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;
您也可以将列类型转换为CHAR(9)。
答案 1 :(得分: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;
刚试过,它工作正常, 我也会尝试你的版本
编辑: 我的疑问:
+-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | Last_query_cost | 16.599000 | +-----------------+-----------+
vs你的
+-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | Last_query_cost | 3.599000 | +-----------------+----------+