对于所有只使用单个查询语句的纯粹主义者来说,假设使用Oracle数据库,一些instr/substr/decode/to_number奇技淫巧可以解决它。
SELECT *
FROM Requirements
WHERE Release NOT LIKE %Obsolete%
ORDER BY
to_number(
substr( reqnum, 1, instr( reqnum, . ) - 1 )
)
, to_number(
substr(
reqnum
, instr( reqnum, . ) + 1 -- start: after first occurance
, decode(
instr( reqnum, . , 1, 2 )
, 0, length( reqnum )
, instr( reqnum, . , 1, 2 ) - 1
) -- second occurance (or end)
- instr( reqnum, . , 1, 1) -- length: second occurance (or end) less first
)
)
, to_number(
decode(
instr( reqnum, . , 1, 2 )
, 0, null
, substr(
reqnum
, instr( reqnum, . , 1, 2 ) + 1 -- start: after second occurance
, decode(
instr( reqnum, . , 1, 3 )
, 0, length( reqnum )
, instr( reqnum, . , 1, 3 ) - 1
) -- third occurance (or end)
- instr( reqnum, . , 1, 2) -- length: third occurance (or end) less second
)
)
)
, to_number(
decode(
instr( reqnum, . , 1, 3 )
, 0, null
, substr(
reqnum
, instr( reqnum, . , 1, 3 ) + 1 -- start: after second occurance
, decode(
instr( reqnum, . , 1, 4 )
, 0, length( reqnum )
, instr( reqnum, . , 1, 4 ) - 1
) -- fourth occurance (or end)
- instr( reqnum, . , 1, 3) -- length: fourth occurance (or end) less third
)
)
)
;
我怀疑其中有很多注意事项,包括:
- assumption of the presence of minor version (second)
- limited to four versions as specified in question s comments