2012-02-20 32 views
2

我有一组类型的表。MySQL的选择Set分离

这个领域是一个彩色标签:

set('Red', 'Blue', 'Green') 

每条记录​​可以有多种颜色,如:

红色和蓝色

现在,当我选择,我得到:

红,蓝,绿

是否有可能将其更改为:

蓝 - 绿 - 红

感谢

回答

0

尝试

select substr(concat(
    if(color='Blue', ' - Blue', ''), 
    if(color='Green',' - Green', ''), 
    if(color='Red',' - Red','') 
), 3) as customfield 
+1

所以如果我有更多的颜色,我将不得不每次更改我的查询? – 2012-02-21 00:54:16

+0

是的,否则你必须创建一个storedprocedure – silly 2012-02-21 04:54:04