zoukankan      html  css  js  c++  java
  • 空值排序(oracle/sqlserver)

     oracle认为 null 最大。

        升序排列,默认情况下,null值排后面。

        降序排序,默认情况下,null值排前面。

        改变空值办法:

        (1)用nvl函数或decode函数将null转换为一特定值

        替换null: nvl(arg,value)

        (2)用case语法将null转换为一特定值(oracle9i以后版本支持。和sqlserver类似):

        order by (case mycol when null then‘北京漂客’else mycol end)

        (3)使用nulls first 或者nulls last 语法。

        null值排序的语法

        nulls first :将null排在最前面。如:

        select *

        from mytb

        order by mycol nulls first

        null last :将null排在最后面。如:

        select *

        from mytb

        order by mycol nulls last

        sqlserver 认为 null 最小。

        升序排列:null 值默认排在最前。

        要想排后面,则:order by case when col is null then 1 else 0 end ,col

        降序排列:null 值默认排在最后。

        要想排在前面,则:order   by case when col is null then 0 else 1 end , col desc

        替换null:isnull(arg,value)

  • 相关阅读:
    C#拾遗(一、基本类型)
    JS正则表达式的test()方法检查汉字
    从程序员到项目经理(一)
    程序员基本素质要求
    似乎比较快
    Qt常用类
    QT 获取窗口 大小 信息
    QT 获取屏幕尺寸的法子
    Qt中 QString 和int, char等的“相互”转换
    qt 读取xml文件
  • 原文地址:https://www.cnblogs.com/volare/p/4310493.html
Copyright © 2011-2022 走看看