如何在数据库表中查询性别的取值,如果为‘M’,显示‘男’,如果为‘F’,显示‘女’?

解决方案 »

  1.   

    select case col when 'M' then '男' else '女' end as 性别  from tb
      

  2.   

    select (case sex_col when 'M' then '男' when 'F' then '女' end) [性别] from tab
      

  3.   

    SELECT 性别=case when col='M' then '男' when col='F' then '女' end from tb
      

  4.   

    select case col when 'M' then '男' else '女' end as 性别 from tb
      

  5.   

    楼上正解,做简单说明,“性别”为查询结果的列名,"col"为数据表中的列名
      

  6.   

     SELECT case col when 'M' then '男' when 'F' then '女' end from tb
      

  7.   

     select  case col
        when 'M' then ‘男’
        when  ‘F’  then  ‘女’
     end 
    from tb
      

  8.   

    select case col when 'M' then '男' else '女' end as 性别 from tb