zoukankan      html  css  js  c++  java
  • 经典SQL语句(case when then)用法

    有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,
    请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路):
    大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。
    显示格式:
    语文 数学 英语
    及格 优秀 不及格

    SQL: select
    case
    when yw<60 then '不及格'
    when yw>=60 and yw<70 then '及格'
    when yw >=70 and yw<80 then '优秀'
    when yw >80 then '优良'

    end as '语文',

    case
    when sx<60 then '不及格'
    when sx>=60 and sx <70 then '及格'
    when sx >=70 and sx<80 then '优秀'
    when sx >80 then '优良'

    end as '数学'
    from St

    从帮助文档中,获知
    1.CASE 函数的另一个用途给数据分类。下面的查询使用 CASE 函数对价格分类。
    2.CASE 函数用于计算多个条件并为每个条件返回单个值。CASE 函数通常的用途是使用可读性更强的值替换代码或缩写

  • 相关阅读:
    转Vtype扩展
    Can't connect to MySQL server on 'ip' (13)
    观察者+js 模式
    (转)ASP.NET架构分析
    sql得到时间
    Js+XML 操作 (转)
    js中的math对象
    property和attribute的区别
    CSS样式定义
    linux 开启 mount
  • 原文地址:https://www.cnblogs.com/lvfeilong/p/dfasdfdsfds.html
Copyright © 2011-2022 走看看