select
*
from
question sq
where
sq.bn_id = 183
order by
nvl(length(trim(sq.answers)),0) desc
-- nvl(attribute,default value) 当属性值为空时就将其值设默认值
-- length(attrbute) 得到字符串的长度
-- trim(attribute) 去掉字符的空格
本文介绍了一种使用SQL查询特定字段的方法,通过nvl、length及trim等函数组合实现对记录按答案长度降序排列。此技巧适用于数据库管理及数据检索场景。
select
*
from
question sq
where
sq.bn_id = 183
order by
nvl(length(trim(sq.answers)),0) desc
-- nvl(attribute,default value) 当属性值为空时就将其值设默认值
-- length(attrbute) 得到字符串的长度
-- trim(attribute) 去掉字符的空格

被折叠的 条评论
为什么被折叠?