生成自然順序,和自定義順序的編號
select 'e' || trim(to_char(nvl(a, 0), '00000000')) customer_id--固定位數填充
from (select t.a, t1.a b
from (select rownum a
from dual
connect by rownum <=
(select max(to_number(replace(customer_id, 'e', ''))) + 2
from tb_cus_firm
where customer_id like 'e%')) t,
(select to_number(replace(customer_id, 'e', '')) a
from tb_cus_firm
where customer_id like 'e%') t1
where t.a not like '%4%' and t.a = t1.a(+))
where b is null and rownum = 1
解析:select a,rownum
from (select t.a, t1.a b
from (select rownum a
from dual
connect by rownum <=
(select max(to_number(replace(customer_id, 'e', ''))) + 2
from tb_cus_firm
where customer_id like 'e%')) t,
(select to_number(replace(customer_id, 'e', '')) a
from tb_cus_firm
where customer_id like 'e%') t1
where t.a not like '%4%' and t.a = t1.a(+))
/*where b is null*/ /*and rownum = 1*/ rownum是根據當前的結果集在作用域內變化,這句就保證了跳過之後還從未用的順序開始
同樣的兩列比較:取理論上對比實際為null的那些的第乙個
ORACLE自定義順序排序
oracle可以借助decode函式,自定義順序排序 select from select nick as item from dual union allselect viki as item from dual union allselect glen as item from dual uni...
ORACLE自定義順序排序
oracle可以借助decode函式,自定義順序排序 select from select nick as item from dual union allselect viki as item from dual union allselect glen as item from dual uni...
mysql按自定義順序排序
order by field 排序列,value1,value2.desc asc select from sy cd ms base hospital info order by field grade,三甲 三乙 三丙 二甲 asc 圖中按照 三甲 三乙 三丙 二甲 的順序排列,沒有在排序中包含...