蓝狐的技术思考 BlueFox Thinking in Tech...
交流,分享,探讨技术...... Communication, Sharing, and Discussion about Technology.....

导航

 

问题:查询用户姓名,性别,根据用户表中的sex字段(bit型),显示性别的值:
当sex为1时,显示'男';当sex为0时,显示'女',要求用一条SQL语句完成.

题解:
      语句1:使用union做联合查询
           select userid,sex='男' from systemmanage..users where sex=1 union
           select userid,sex='女' from systemmanage..users where sex=0
     语句2:使用case做条件查询
           select userid,sex= case sex when 0 then '女' when 1 then '男' end
           from systemmanage..users 
欢迎给出其它答案?
       

posted on 2006-09-07 01:00  蓝狐  阅读(166)  评论(0编辑  收藏  举报