在資料開發應用中,很多時候需要對資料進行排序,但是在
oracle
資料庫中,有空值一說
(null)
。如果乙個列中有的值是空的,則如果對此列進行排序的話,空值的行將被排序放到後面,如我對
hr模式下的
employees
員工表按照佣金比率列進行排序的話,
select t.employee_id, t.last_name, t.commission_pct
from employees t
where t.employee_id between 178 and 181
order by t.commission_pct
結果如下:
179 johnson 0.10
178 grant 0.15
180 taylor
181 fleaur
180,
181由於沒有佣金比率被排到了後面
而有的時候我們希望將空值的記錄排序在前面而不是後面
,這時候則需要使用關鍵字:
nulls first:將空值的記錄排序在前面
nulls last:將空值的記錄排序在後面(預設
) 例如上面的例子做少許的修改:
select t.employee_id, t.last_name, t.commission_pct
from employees t
where t.employee_id between 178 and 181
order by t.commission_pct nulls first
結果如下:
180 taylor
181 fleaur
179 johnson 0.10
178 grant 0.15
180,
181由於沒有佣金比率被排到了前面
django orm排序 空值在後
from django.db.models import q,faq q net number icontains demo.objects.filter aq order by f test time asc nulls last true start end values 其中test time...
oracle 空值處理,排序過濾
oracle認為 null 最大。公升序排列,預設情況下,null值排後面。降序排序,預設情況下,null值排前面。有幾種辦法改變這種情況 1 用 nvl 函式或decode 函式 將null轉換為一特定值 2 用case語法將null轉換為一特定值 oracle9i以後版本支援。和sqlserve...
公升序排序空值排在最後
table 待排序表名 column 待排序屬性 select from table orderby column isnull column asc list 待排序的實體集合 entity 實體 column 排序字段 type 排序字段型別 list.stream sorted compara...