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

  • 相关阅读:
    HDU 4069 Squiggly Sudoku
    SPOJ 1771 Yet Another NQueen Problem
    POJ 3469 Dual Core CPU
    CF 118E Bertown roads
    URAL 1664 Pipeline Transportation
    POJ 3076 Sudoku
    UVA 10330 Power Transmission
    HDU 1426 Sudoku Killer
    POJ 3074 Sudoku
    HDU 3315 My Brute
  • 原文地址:https://www.cnblogs.com/poli/p/4109157.html
Copyright © 2011-2022 走看看