zoukankan      html  css  js  c++  java
  • SQL7:CASE语句

    --case用于不等的判断
    --优化:低于60分的学生提示不及格
    select tsname,
    isnull(
    case when tEnglish<60 then '不及格' else CAST(tEnglish as varchar(10)) end
    ,'缺考')
    from TblStudent
    left join TblScore on TblStudent.tSId=TblScore.tSId

    --判断等的情况
    use hem09

    select * from Employee
    update Employee set eGender=1 where eName='sk'

    --将性别显示成男和女
    select *,case egender when 0 then '男' when 1 then '女' end
    from Employee

    --有一个财务流水表
    --MoneyFlow fid fTitle fMoney
    create table MoneyFlow
    (
    fid int identity(1,1) primary key not null,
    ftitle nvarchar(10),
    fmoney money
    )

    select * from MoneyFlow
    insert into MoneyFlow values('发工资',1000)
    insert into MoneyFlow values('奖金',500)
    insert into MoneyFlow values('捡钱',200)
    insert into MoneyFlow values('请客',-1500)
    insert into MoneyFlow values('洗脚',-3000)

    select fid,ftitle,case when fmoney>0 then fmoney else 0 end as '收入',
    case when fmoney<0 then ABS(fmoney) else 0 end as '支出'
    from MoneyFlow

  • 相关阅读:
    UE4 Abc 批量导入
    UE4源码摘录(424)
    JZ10 矩形覆盖
    JZ27 字符串的排列
    JZ66 机器人的运动范围
    JZ65 矩阵中的路径
    JZ12 数值的整数次方
    JZ37 数字在升序数组中出现的次数
    JZ6 旋转数组的最小数字
    JZ67 剪绳子
  • 原文地址:https://www.cnblogs.com/poli/p/4109157.html
Copyright © 2011-2022 走看看