学生成绩表学号 姓名 分数 1    a   90 2    b   60 3    c   40           查询学生成绩表,显示结果如下:学号 姓名 分数 成绩 1    a   90  及格 2    b   60  及格 3    c   40  不及格sql serverC#

解决方案 »

  1.   

    select *,[成绩]=(case when 分数<60 then '不及格' else '及格' end) from tb
      

  2.   

    select *,[成绩]=CAST((case when 分数<60 then '不及格' else '及格' end) AS NVARCHAR(10)) from tb 
      

  3.   

    create table student
    (
      stuNo int ,
      stuName varchar(50),
      stuScore varchar(50)
    )
    insert into student
    select 1,'a',90 union all
    select 2,'b',60 union all
    select 3,'c',40 select stuNo '学号',stuName '姓名',stuScore '分数',
       case when stuScore>60 then '及格'
       else '不及格'
       end '成绩'
    from student学号          姓名           分数            成绩
    ----------- ------------------------------------------- 
    1           a                  90             及格
    2           b                  60             不及格
    3           c                  40             不及格(3 行受影响)
      

  4.   


    create table student
    (
      stuNo int ,
      stuName varchar(50),
      stuScore varchar(50)
    )
    insert into student
    select 1,'a',90 union all
    select 2,'b',60 union all
    select 3,'c',40 
     
    select stuNo '学号',stuName '姓名',stuScore '分数',
       case when stuScore>=60 then '及格'
       else '不及格'
       end '成绩'
    from student
     
    学号          姓名           分数            成绩
    ----------- ------------------------------------------- 
    1           a                  90             及格
    2           b                  60             及格
    3           c                  40             不及格
     
    (3 行受影响)