怎样把1转换成"是",0转换成"否"?
在oracle中用decode(colname,1,'是',0,'否')可以,在mysql中应该用什么函数怎样写?

解决方案 »

  1.   

    SQL SERVER 中    CASE colname WHEN 1 THEN '是' WHEN 0 THEN '否' END这里应该也是可以的
    兄弟 试试 看
      

  2.   

    如果你那一行定义为int(1)
    那么你需要先修改为char(2)
    然后update table set col='是' where col='1';
      

  3.   

    下面的例子不知道对你有没有帮助,我用的mysql 5.0.23.
    mysql> use test;
    Database changed
    mysql> create table aa (id int not null auto_increment primary key,
        -> name varchar(24) not null,sex char(4));
    Query OK, 0 rows affected (0.13 sec)
    mysql> insert into aa values(1,'jim','1');
    Query OK, 1 row affected (0.03 sec)mysql> insert into aa values(2,'lily','0');
    Query OK, 1 row affected (0.00 sec)mysql> select * from aa;
    +----+------+------+
    | id | name | sex  |
    +----+------+------+
    |  1 | jim  | 1    |
    |  2 | lily | 0    |
    +----+------+------+
    2 rows in set (0.02 sec)mysql> update aa set sex=if(sex,'男','女');
    Query OK, 2 rows affected (0.00 sec)
    Rows matched: 2  Changed: 2  Warnings: 0mysql> select * from aa;
    +----+------+------+
    | id | name | sex  |
    +----+------+------+
    |  1 | jim  | 男   |
    |  2 | lily | 女   |
    +----+------+------+
    2 rows in set (0.00 sec)