字段都是enum类型的,枚举变量是用汉字表示的!
比如 enum('新闻','博客','论坛')。
而我现在希望将同一条记录中几个这样的字段连接成一个字符串,如:
"博客/供求/负面"如何做到?

解决方案 »

  1.   

    select concat(col1,col2) from xxx
      

  2.   

    用CONCAT即可
    select concat('123',456,'博客/供求/负面')
      

  3.   

    select concat('博客','/','供求','/','负面')
      

  4.   

    mysql> create table t_netxuning (
        ->  id int,
        ->  col1 enum('新闻','博客','论坛'),
        ->  col2 enum('新闻','博客','论坛')
        -> );
    Query OK, 0 rows affected (0.45 sec)mysql> select * from t_netxuning;
    +------+------+------+
    | id   | col1 | col2 |
    +------+------+------+
    |    1 | 新闻 | 博客 |
    |    2 | 博客 | 论坛 |
    |    3 | 论坛 | 新闻 |
    +------+------+------+
    3 rows in set (0.00 sec)mysql> select id,concat(col1,'/',col2) from t_netxuning;
    +------+-----------------------+
    | id   | concat(col1,'/',col2) |
    +------+-----------------------+
    |    1 | 新闻/博客             |
    |    2 | 博客/论坛             |
    |    3 | 论坛/新闻             |
    +------+-----------------------+
    3 rows in set (0.00 sec)mysql> select group_concat(col1 SEPARATOR '/') from t_netxuning;
    +----------------------------------+
    | group_concat(col1 SEPARATOR '/') |
    +----------------------------------+
    | 新闻/博客/论坛                   |
    +----------------------------------+
    1 row in set (0.00 sec)mysql>